﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace WpfApp12
{
    public class MyControl : FrameworkElement
    {
        public string UserName
        {
            get => (string)GetValue(UserNameProperty);
            set => SetValue(UserNameProperty, value);
        }

        public readonly static DependencyProperty UserNameProperty;

        static MyControl()
        {
            FrameworkPropertyMetadata metadata = new FrameworkPropertyMetadata("123")
            {
                AffectsArrange = true,
                AffectsMeasure = true,
                AffectsParentArrange = true,
                AffectsParentMeasure = true,
                CoerceValueCallback = MyCoerceValue,
                PropertyChangedCallback = MyPropertyChanged
            };

            UserNameProperty = DependencyProperty.Register("UserName", typeof(string), typeof(MyControl), metadata, new ValidateValueCallback(MyValidate));
        }

        private static bool MyValidate(object value)
        {
            return true;;
        }

        private static object MyCoerceValue(DependencyObject d, object baseValue)
        {
            return baseValue;
        }

        private static void MyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            
        }

      
    }
}
